import React, { Component, PropTypes } from 'react';
import $ from "jquery";
import action from '../../../Action/Index';



class ListItem1 extends Component {
    constructor(props) {
        super(props)
        this.state = {
            isFreshing: false
        }

        this.onGroup = (e) => {
            if (!this.state.isFreshing) {
                this.setState({
                    isFreshing: true
                })
            }
            let id = e.target.id;
            $("#showRender a").removeClass('active');
            $(e.target).addClass('active');
            this.onClickGroup(id)
            setTimeout(_ => {
                this.setState({
                    isFreshing: false
                })
            }, 3000)
        }
    }
    addActive() {
        $("#showRender a:first").addClass('active');
    }
    groupItem() {
        let {dispatch} = this.props;
        let id = $("#showRender a:first").get(0).id;
        dispatch(action.fetchGroupItem(id));
    }
    onClickGroup(id) {
        let {dispatch} = this.props;
        dispatch(action.fetchGroupItem(id));
    }
    render() {
        let {id, classifyName, sort} = this.props;

        return (
            <a className="render-item mui-ellipsis" onClick={this.onGroup} ref="ggg" href="javascript://" id={id}>{classifyName}</a>
        );
    }
    shouldComponentUpdate(np) {
        return false;
        // return this.props.tab !== np.tab; //tab和之前的不一致，组件才需要更新，否则不更新，提升性能
    }
    componentDidMount() {
        this.addActive();
        this.groupItem();
    }
}

export default ListItem1;